/*
 * 签名生成	
 * kAppKey,kAppSecret为常量，
 * params，传入的参数，string || object
 * 需要借助md5.js
 * 规则：将所有参数字段按首字母排序， 拼接成key1 = value1 & key2 = value2的格式，再在末尾拼接上key = appSecret， 再做MD5加密生成sign
 */
import md5Libs from "@/uview-ui/libs/function/md5";
export function getSign (params) {
    if (typeof params == 'string') {
        return paramsStrSort(params)
    } else if (typeof params == 'object') {
        var arr = []
        for (var i in params) {
            //if(typeof params[i] != 'object' && i != 'sign' && params[i]){
			if(typeof params[i] != 'object' && i != 'sign'){	
                arr.push((i + '=' + params[i]))
            }
        }
        return paramsStrSort(arr.join(('&')))
    }
}

export function paramsStrSort (paramsStr) {
  // var config = wx.getExtConfigSync ? wx.getExtConfigSync() : {}//获取配置
  //console.log(config);
  // #ifdef  MP-WEIXIN
		var url = paramsStr + '&appid=wx0b0f65b3eb8511bb'
		var urlStr = url.split('&').sort().join('&')
		var newUrl = urlStr
		console.log(newUrl)
		return md5Libs.md5(newUrl).toUpperCase()
  // #endif
  
  // #ifdef  MP-ALIPAY
		var url = paramsStr + '&appid=2021003156639349'
		var urlStr = url.split('&').sort().join('&')
		var newUrl = urlStr
		console.log(newUrl)
		return md5Libs.md5(newUrl).toUpperCase()
  // #endif
  
  // #ifdef  MP-TOUTIAO
		var url = paramsStr + '&appid=ttebc79d7a74f9bbc201'
		var urlStr = url.split('&').sort().join('&')
		var newUrl = urlStr
		console.log(newUrl)
		return md5Libs.md5(newUrl).toUpperCase()
  // #endif
}